package cn.zjh.controller;

import cn.zjh.domian.User;

import cn.zjh.feigen.UserFeignClient;
import cn.zjh.sentinel.OrderBlockHandler;
import cn.zjh.sentinel.OrderFallbackClass;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/getById/{id}")
    @SentinelResource(value = "order-getById",
            blockHandler = "getByIdBlockHandler",
            blockHandlerClass = OrderBlockHandler.class,
            fallback = "getByIdFallback",
            fallbackClass = OrderFallbackClass.class)
    public User getById(@PathVariable("id") Long id){
        // 调用OpenFeign接口，通信User服务
        return userFeignClient.getById(id);
    }

}
